package com.exam.api.modules.system.controller.manager;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.lang.tree.Tree;
import com.exam.api.common.web.TinyResponse;
import com.exam.api.modules.system.domain.TblMenu;
import com.exam.api.modules.system.dto.MenuAddDTO;
import com.exam.api.modules.system.dto.MenuIdDTO;
import com.exam.api.modules.system.dto.MenuQueryDTO;
import com.exam.api.modules.system.dto.MenuUpdateDTO;
import com.exam.api.modules.system.service.TblMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * (管理端) 菜单相关接口
 *
 * @author bcheng
 */
@Tag(name = "(管理端) 菜单相关接口", description = "(管理端) 菜单相关接口")
@RestController
@RequestMapping("/manager/menu")
@SaCheckLogin
@TinyResponse
public class MenuManagerController {

    @Resource
    private TblMenuService tblMenuService;

    @Operation(summary = "当前登录的权限列表", description = "当前登录的权限列表")
    @PostMapping("/codes")
    public List<String> listManagerPermissionCodes() {
        return tblMenuService.listManagerPermissionCodes();
    }

    @Operation(summary = "当前登录的权限树", description = "当前登录的权限树")
    @PostMapping("/tree")
    public List<Tree<Long>> listManagerMenuTree(@RequestBody @Validated MenuQueryDTO dto) {
        return tblMenuService.listManagerMenuTree(dto);
    }

    @Operation(summary = "全部菜单树", description = "全部菜单树")
    @PostMapping(value = {"/list"})
    public List<Tree<Long>> treeMenu(@RequestBody @Validated MenuQueryDTO dto) {
        return tblMenuService.treeMenu(dto);
    }

    @Operation(summary = "菜单信息", description = "菜单信息")
    @PostMapping("/info")
    public TblMenu getMenu(@RequestBody @Validated MenuIdDTO dto) {
        return tblMenuService.getMenu(dto);
    }

    @Operation(summary = "新增菜单", description = "新增菜单")
    @PostMapping("/add")
    public void addMenu(@RequestBody @Validated MenuAddDTO dto) {
        tblMenuService.addMenu(dto);
    }

    @Operation(summary = "更新菜单", description = "更新菜单")
    @PostMapping("/update")
    public void updateMenu(@RequestBody @Validated MenuUpdateDTO dto) {
        tblMenuService.updateMenu(dto);
    }

    @Operation(summary = "删除菜单", description = "删除菜单")
    @PostMapping("/delete")
    public void deleteMenu(@RequestBody @Validated MenuIdDTO dto) {
        tblMenuService.deleteMenu(dto);
    }
}
